package day01;

import java.util.LinkedList;

/**
 * @author Jetwang
 * @version 1.0
 * @since 2023/3/12 12:22
 * 力扣 225. 用队列实现栈
 */
public class StackPractice05 {

    LinkedList<Integer> list01 = new LinkedList<>();
    LinkedList<Integer> list02 = new LinkedList<>();

    public StackPractice05() {

    }

    public void push(int x) {
        while(!list01.isEmpty()) {
            list02.offer(list01.poll());
        }
        list01.offer(x);
        while(!list02.isEmpty()) {
            list01.offer(list02.poll());
        }
    }

    public int pop() {
        if (list01.isEmpty()) {
            return -1;
        } else {
            return list01.poll();
        }
    }

    public int top() {
        if (list01.isEmpty()) {
            return -1;
        } else {
            return list01.peek();
        }
    }

    public boolean empty() {
        return list01.isEmpty() && list02.isEmpty();
    }
}
